Replace "witness only" with "non native felt op" attribute on felt arith ops#288
Replace "witness only" with "non native felt op" attribute on felt arith ops#288tim-hoffman merged 4 commits intomainfrom
Conversation
Use this on field ops that may appear in constrain code but must be eventually be rewritten in terms of native fields ops or folded to a constant.
| - "Add `function.allow_non_native_field_ops` attribute" | ||
| changed: | ||
| - "Require `function.allow_non_native_field_ops` attribute on functions that use | ||
| non-native field operations, instead of requiring `function.allow_witness` attribute." |
There was a problem hiding this comment.
I'm missing context I think, but does this mean allow_non_native_field_ops subsumes allow_witness everywhere? Or are there still cases where you might want one or the other on @compute but not both?
There was a problem hiding this comment.
This is more for @constrain, where some ops that are not allowed in the constraint backend (e.g., felt.umod) can be allowed earlier in the pipeline for values that will eventually be flattened into constants (e.g., computing an index i % 4 is allowed in @constrain if i will be known at compile time, but we currently don't have a way to encode that)
There was a problem hiding this comment.
@raghav198 I added a description on the PR that hopefully explains it fully but let me know if anything remains unclear
iangneal
left a comment
There was a problem hiding this comment.
Are we planning to do a different PR to allow @constrain functions to have the new attribute? Otherwise LGTM
Nothing preventing that now. I'll add a test. |
The
WitnessGentrait on felt ops is too restrictive because there are scenarios where there exists no way to represent the code in the@constrainfunction without them (e.g.,array.read a[i % 4]whereiis a loop index variable). TheNotFieldNativetrait allows a less restrictive verification on these ops, allowing them to exist even in the@constrainfunction until the flattening pass (i.e. struct instantiation and loop unrolling) is later performed. After the flattening pass and constant folding, all such ops should be removed or handled in a manner specific to the backend.